<?php
include "sso.php";
header('content-type:text/html;charset=utf-8');

$username=$_POST['username'];
$password=$_POST['password'];
$verifiCode=$_POST['verifiCode'];

if ($username && $password && $verifiCode) {
    $ssoLogin = new SSO();
    $tokenGet = $ssoLogin->token($username, $password, $verifiCode);
    if ($tokenGet['code']==1) {
        setcookie('token', $tokenGet['token'], time()+30, '/', 'localhost', false, true); // 最后一个参数httponly
        echo "登陆成功!";
    } elseif ($tokenGet['code']==-1) {
        echo "用户不存在，请先注册...";
    } else {
        echo "密码错误，请重新登录!";
    }

    unset($ssoLogin); // 销毁SSO对象
} else {
    echo "请重新登录...";
}
